AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include( "shared.lua" )
include( "resources.lua" )

--[[---------------------------------------------------------
	CONSTANTS
-----------------------------------------------------------]]
local KillReasons = {
	"killed",
	"destroyed",
	"eviscerated",
	"mutilated",
	"maimed",
	"broken",
	"torn apart",
	"severed",
	"annihilated",
	"blistered",
	"smoked",
	"wiped out",
	"brutalized",
	"mangled",
	"butchered",
	"executed",
	"slain",
	"frayed",
	"owned",
	"demolished",
	"desecrated",
	"clobbered",
	"trashed",
	"rocked",
	"defeated",
	"wrecked",
	"assassinated",
	"plundered",
	"hunted down",
	"blasted"
}

local SuicideReasons = {
	"bit the dust.",
	"had enough.",
	"committed suicide.",
	"is pushing up daisies.",
	"thought they were invincible.",
	"is sleeping with the fishes.",
	"sacrificed themselves.",
	"died.",
	"gave blood to the gods.",
	"saw no reason to live.",
	"ended themselves."
}

--	Initialize the server-side only parts
function GM:Initialize()
	
	--	Call base
	self.BaseClass:Initialize()
	
	--	Debug
	DEBUG:Msg( self.Name .. " has been initialized" )
	
end

-- List of weapons for random loadout, kinda stupid atm but w/e
local Primaries = {
"weapon_sigma_m4",
"weapon_sigma_m3",
"weapon_sigma_famas",
"weapon_sigma_galil",
"weapon_sigma_p90",
"weapon_sigma_mp5",
"weapon_sigma_ak47",
"weapon_sigma_rpg",
"weapon_sigma_mac10"
}

local Secondaries = {
"weapon_sigma_deagle",
"weapon_sigma_usp",
"weapon_sigma_p228"
}

--	A player spawns
function GM:PlayerSpawn( ply )
	
	--	Call base
	self.BaseClass:PlayerSpawn( ply )
	
	ply:SetArmor( 100 )
	
	--	Give default weapons to player

	ply:Give( table.Random( Primaries ) )
	ply:Give( table.Random( Secondaries ) )
	
	--	Give related ammo
	ply:GiveAmmo( 200, "AR2", true )
	ply:GiveAmmo( 60, "Pistol", true )
	ply:GiveAmmo( 20, "Buckshot", true )
	ply:GiveAmmo( 100, "smg1", true )
	ply:GiveAmmo( 5, "rpg_round", true )
	
	--	Notify about loadout
	ply:PrintMessage( 3, "[SC] Loadout given.\n" )
	
	--	Set speed ratios
	ply:SetRunSpeed( 200 )
	ply:SetWalkSpeed( 100 )
end

function ChatKillFeed( victim, weapon, killer )

	local krFeed = table.Random( KillReasons )
	local suFeed = table.Random( SuicideReasons )

	--	Notify dumbass kamikaze
	if (victim == killer) then 
		PrintMessage( 3, victim:GetName() .. " " .. suFeed )
	
	--	Notify dead player
	else
		PrintMessage( 3, victim:GetName() .. " was " .. krFeed .. " by " .. killer:GetName() )
	end

end 
hook.Add( "PlayerDeath", "playerDeathTest", ChatKillFeed )

function GM:GetFallDamage( ply, vel )
	return ( vel - 480 ) * ( 100 / ( 1024 - 580 ) )
end

function GM:ScalePlayerDamage( ply, hitgroup, dmginfo )

	--	Headshots
	if 		hitgroup == HITGROUP_HEAD then
		dmginfo:ScaleDamage( 10 )
		dmginfo:GetAttacker():PrintMessage( 3, "Headshot!\n" )

	--	Body shots
	elseif 	hitgroup == HITGROUP_STOMACH or
			hitgroup == HITGROUP_GENERIC or
			hitgroup == HITGROUP_CHEST	then
		dmginfo:ScaleDamage( 3 )

	--	Arm / leg shots
	elseif 	hitgroup == HITGROUP_LEFTARM or
			hitgroup == HITGROUP_RIGHTARM or
			hitgroup == HITGROUP_LEFTLEG or
			hitgroup == HITGROUP_RIGHTLEG or
			hitgroup == HITGROUP_GEAR then
		dmginfo:ScaleDamage( 2 )
	end
	
	--	Notify attacker
	if dmginfo:GetAttacker():IsPlayer() then
      dmginfo:GetAttacker():PrintMessage( 3, "Dealt "..dmginfo:GetDamage().. " damage.\n" )
	end
	
end